#include "stdafx.h"
#include "PlunderHonorDrop.h"
#include "InstanceTouch.h"
#include <algorithm>
DECL_INSTANCE_TOUCH(ETouch_PlunderHonorDrop);

struct  PlunderHonorDropDefReflectionRegister
{
	PlunderHonorDropDefReflectionRegister()
	{
		REGISTER_REFLECTION_MEMBER(PlunderHonorDrop,m_iID,INVALID_ID).Editor_SetAsPrimaryKey();
		REGISTER_REFLECTION_MEMBER(PlunderHonorDrop,m_sDisplayName,std::string("DefaultName")).Editor_SetAsDisplayName();
		REGISTER_REFLECTION_MEMBER(PlunderHonorDrop,m_iPlayerToLvl,1).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(PlunderHonorDrop,m_iWinDropID,INVALID_ID).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(PlunderHonorDrop,m_iFailedDopID,INVALID_ID).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(PlunderHonorDrop,m_iDropCount,5).Editor_SetAsRaw();
		
		GlobalClassManager::Instance().RegisterClass(PlunderHonorDrop::s_GetReflection(),eDefaultDef_PlunderHonorDrop);
		GlobalDefManager::Instance().RegisterDefManger(&PlunderHonorDropManager::Instance());

	}
}___PlunderHonorDropDefReflectionRegister;

rewrite  void PlunderHonorDrop::OnArchieveReaded()
{
}
static bool __CompareByLvl(const PlunderHonorDrop* pA,const PlunderHonorDrop* pB)
{
	return pA->m_iPlayerToLvl<pB->m_iPlayerToLvl;
}
void PlunderHonorDropManager::OnArchieveReaded()
{
	__PlunderHonorDropManager::OnArchieveReaded();
	m_vSortedList.clear();
	this->Enumerate(m_vSortedList);
	std::sort(m_vSortedList.begin(),m_vSortedList.end(),__CompareByLvl);
}

const PlunderHonorDrop* PlunderHonorDropManager::LookupPlunderHonorDropByLvl( int32 iLvl )
{
	for(uint32 ii=0;ii<m_vSortedList.size();ii++)
	{
		if(m_vSortedList[ii]->m_iPlayerToLvl>=iLvl)
		{
			return m_vSortedList[ii];
		}
	}
	return NULL;
}